function scmat=counts(smat,nums);
% function cmat=counts(smat,nums);
% Counts the number of times a given state was generated in a matrix of draws 
% cmat is (number of states  x number of observations) 
% Rows corresponds to states
% Columns correspond to observations
% Each and inducates the 
% the (s,t) entry of cmat is the proportion of simulations 
% in which state s was drawn at time t 
[ndraws,T]=size(smat); 
sind=1:nums; 
scmat=zeros(nums,T); 
ii=1; 
for jj=1:nums-1; 
    tmat=zeros(ndraws,T); 
    indt=find( smat == sind(jj) ); 
    tmat(indt) = 1; 
    scmat(jj,:) = sum(tmat,1)/ndraws;
end; 
scmat(end,:) = ones(1,T) - sum( scmat(1:nums-1,:),1 ); 
